<?php

namespace App\Http\Controllers\Client\Activity;

use App\Http\Controllers\ClientController;
use App\Models\Tools\Data;
use Illuminate\Support\Facades\DB;

class LotteryBuyBeforeController extends ClientController
{
    /**
     * 霸王餐购买前的处理
     */
    public function index()
    {
        /**
         * 验证是否已经绑定了店铺和霸王餐策略
         */
        $shop = DB::table('shop')->where('we_id', '=', $this->we_id)->count();
        $goods = DB::table('lottery_goods')->where('creator', '=', $this->we_id)->count();

        $verified_phone = DB::table('lottery_users')->where('we_id', '=', $this->we_id)->value('phone');

        // 店铺审核状态
        $verified_shop = DB::table('shop')
            ->where('we_id','=',$this->we_id)
            ->where('verified','=',Data::DATA_DB_LAIFEI_SHOP_VERIFIED_SUCCESS)
            ->count();

        // 查询已有店铺的店铺类型
        $shop_types = DB::table('shop')
            ->where('we_id','=',$this->we_id)
            ->where('verified','=',1)
            ->pluck('shop_type')
            ->toArray();

        $shop_types = array_unique($shop_types);

        // 购买条件
        $types = DB::table('shop_type')
            ->whereIn('st_id',$shop_types)
            ->select('st_id as id','name')
            ->get()
            ->toArray();
        // 购买条件
        $list = DB::table('shop_type')
            ->select('st_id as id','lottery_price as price','st_id as s1')
            ->get()
            ->map(function ($item){
                $item->stock_num = 10000;
                return $item;
            })
            ->toArray();


        return $this->setReturnJson(0, 'success', [
            'shop' => $shop && true,
            'goods' => $goods && true,
            'type' => $types,
            'list' => $list,
            'verified_phone' => $verified_phone && true,
            'verified_shop'=>$verified_shop && true,
        ]);

    }

}
